package com.yzf;

import com.amap.api.location.AMapLocation;

/**
 * Created by Administrator on 2016/2/4.
 */
public class Util {
    /**
     *  开始定位
     */
    public final static int MSG_LOCATION_START = 0;
    /**
     * 定位完成
     */
    public final static int MSG_LOCATION_FINISH = 1;

    /**
     * 根据定位结果返回定位信息的字符串
     * @return
     */
    public synchronized static String getLocationStr(AMapLocation location){
        if(null == location){
            return null;
        }
        StringBuffer sb = new StringBuffer();
        //errCode等于0代表定位成功，其他的为定位失败，具体的可以参照官网定位错误码说明
        if(location.getErrorCode() == 0){
            if (location.getProvider().equalsIgnoreCase(android.location.LocationManager.GPS_PROVIDER)) {
            } else {
                sb.append(location.getCity());
            }
        } else {
            //定位失败
            sb.append("定位失败");
        }
        return sb.toString();
    }
}
